package com.mv.controller;

import com.mv.pojo.User;
import com.mv.service.CardService;
import com.mv.service.DealService;
import com.mv.service.UserService;
import com.mv.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/mv")
public class UserController {
    @Autowired
    private UserService userService;
    /*查询会员个数*/
    @GetMapping("/user/getUserCount")
    public SysResult getCount(){
        Integer count=userService.getCount();
        return SysResult.success(count);
    }
    /*根据用户名查询用户ID*/
    @GetMapping("/user/getUserId")
    public SysResult getUserId(String userName){
        Integer userId=userService.getUserId(userName);
        return SysResult.success(userId);
    }
    /*获取用户名*/
    @GetMapping("/user/getUserName")
    public SysResult getUserName(){
        List<User> userList=userService.getUserName();
        return SysResult.success(userList);
    }
    /*查*/
    @GetMapping("/user/get")
    public SysResult getUser(String query,String mode){
        List<User> user = userService.getUser(query,mode);
        return SysResult.success(user);
    }
    /*增*/
    @PostMapping("/user/add")
    public SysResult addUser(@RequestBody User user){
        userService.addUser(user);
        return SysResult.success();
    }
    /*删*/
    @DeleteMapping("/user/delete")
    public SysResult deleteUser(Integer id){
        userService.deleteUser(id);
        return SysResult.success();
    }
    /*删除所选会员*/
    @PostMapping("/user/deleteBySelectList")
    public SysResult deleteBySelectList(@RequestBody List<User> selectList){
        userService.deleteBySelectList(selectList);
        return SysResult.success();
    }
    /*改*/
    @PutMapping("/user/putuser")
    public SysResult updateUser(@RequestBody User user){
        userService.updateUser(user);
        return SysResult.success();
    }
}
